package com.coocaa.x.app.hall.view.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.coocaa.x.app.hall.R;
import com.coocaa.x.framework.app.CoocaaApplication;
import com.skyworth.ui.api.SkyToastView;

/**
 * Created by luwei on 15-6-19.
 */
public class TipToast {
    private static TipToast instance = null;
    private SkyToastView toast = null;
    private Context context = null;
    private FrameLayout.LayoutParams params = null;

    public static synchronized TipToast getInstance() {
        if (instance == null)
            instance = new TipToast();
        return instance;
    }

    private TipToast() {
        context = CoocaaApplication.getContext();
    }

    public void showToast(String txt, int time) {
        if (toast == null) {
            toast = new SkyToastView(context);
            params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
            params.bottomMargin = CoocaaApplication.Div(50);
        }
        if (toast.isShowing())
            toast.dismiss();
        toast.setTostString(txt);
        toast.showToast(SkyToastView.ShowTime.LONGTIME, params);
    }

    public void showToast(String txt) {
        showToast(txt, 3000);
    }

    public static final Runnable showNetIsNotConnectedToastRunnable = new Runnable() {
        @Override
        public void run() {
            TipToast.getInstance().showNetToast(false);
        }
    };

    private void showNetToast(boolean isConnect) {
        if (!isConnect) {
            showToast(context.getString(R.string.connect_Internet));
        }
    }
}
